<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

App::import('Vendor', 'cart/jproduct');
class OrderController extends AppController {

    var $layout = 'subpage';
    var $uses = array(
        'Basket', 'Game', 'Basketphoto', 'Share', 'Logo', 'Banner', 'Order'
    );
    var $scripts = array('jquery', 'ui', 'jcarousellite_1.0.1', 'jquery.lightbox-0.5', 'jquery.flash', 'cart', 'custom', 'ui-timepicker','order');

    function index() {
        $this->set('title_for_layout', 'www.Hong3ly.com .:.  trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi');
        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('logo', $this->Logo->getLogo());
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
        $this->set('game_image_thumb_url_path', Configure::read('game_image_thumb_url_path'));
        $this->set('top_games', $this->Game->getTopGame());
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
        $this->set('cart', $this->cart);
    }
    function process(){
        $this->layout = null;
        $form   =   $this->params['form'];
        $product_content    =   array();
        foreach($this->cart->getItems() AS $item){
            $product_content[]    =   array(
                'product_id'    =>  $item->product_id,
                'product_type'  =>  $item->product_type,
                'product_name'  =>  $item->product_name,
                'quantity'      =>  $item->quantity,
                'extra' =>  array()
            );
        }
        $data   =   array(
            'buyer_name'    =>  $form['txtbuyer_name'],
            'buyer_phone'    =>  $form['txtbuyer_phone'],
            'buyer_address'    =>  $form['txtbuyer_address'],
            'buyer_email'    =>  $form['txtbuyer_email'],
            'buyer_birthday'    =>  '',
            'user_id'   =>  $this->Auth->user('id'),
            'buyer_sex'   =>  $form['txtbuyer_sex'],
            'country_id'   =>  $form['list_country'],
            'receiver_name'   =>  $form['txtreceiver_name'],
            'receiver_phone'   =>  $form['txtreceiver_phone'],
            'receiver_address'   =>  $form['txtreceiver_address'],
            'receiver_sex'   =>  $form['txtreceiver_sex'],
            'receiver_district'   =>  $form['list_district'],
            'time_send' =>  '',
            'receiver_email'    =>  $form['txtreceiver_email'],
            'order_content' => serialize($product_content)
        );
        if($this->Order->save($data)){
            echo 1;
        }
        exit;
    }

}

?>
